package framework.common.zanetwork.core;
import android.text.TextUtils;
import android.widget.Toast;

import net.zhuike.novel.app.ZhuiKeApplication;


public class HttpResopnseHandler {

    static final String ignoreUrl[] = {};

    public static boolean HandleError(int code,String msg) {
        if (isIgnore()) {
            return false;
        }
        switch (code){
            case ResponseCode.serverError:
                Toast.makeText(ZhuiKeApplication.getAppContext(), msg, Toast.LENGTH_SHORT).show();
                break;
            case ResponseCode.msgError:
                Toast.makeText(ZhuiKeApplication.getAppContext(), "返回数据错误", Toast.LENGTH_SHORT).show();
                break;
            case ResponseCode.networkError:
                Toast.makeText(ZhuiKeApplication.getAppContext(), "网络连接不可用", Toast.LENGTH_SHORT).show();
                break;
            case ResponseCode.dataError:
                Toast.makeText(ZhuiKeApplication.getAppContext(), "网络不好，稍后重试", Toast.LENGTH_SHORT).show();
                break;
            case ResponseCode.httpError:
                Toast.makeText(ZhuiKeApplication.getAppContext(), "请求错误", Toast.LENGTH_SHORT).show();
                break;
            default:
                if(!TextUtils.isEmpty(msg)){
                    Toast.makeText(ZhuiKeApplication.getAppContext(), msg, Toast.LENGTH_SHORT).show();
                }
                break;

        }
        return false;
    }


    private static boolean isIgnore() {
        for (String s : ignoreUrl) {
            if (HttpHelper.getRequestUrl().contains(s)) {
                return true;
            }
        }
        return false;
    }
}


